package Vista;

import Dominio.Dom_Fachada;
import Dominio.PerfilData;

import com.opensymphony.xwork2.ActionSupport;

public class EliminarTrabajador extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String nif;

	private PerfilData employee;

	public String execute() {
		try {
			employee = new PerfilData(Integer.parseInt(nif));
			new Dom_Fachada().deleteUser(employee);
			return SUCCESS;
		} catch (Exception e) {
			System.err.println(e.toString());
		}
		return ERROR;
	}

	public void validate() {
		if (getNif().length() == 0) {
			addFieldError("nif",
					"El NIF del trabajador es un campo obligatorio.");
		} else if (getNif().length() != 8) {
			addFieldError("nif", "El NIF introducido es inválido.");
		}
	}

	public String getNif() {
		return nif;
	}

	public void setNif(String nif) {
		this.nif = nif;
	}

}
